home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / CARDMATH.MOD < prev    next >
Text File  |  1989-01-18  |  2KB  |  59 lines

  1.                                          (* Chapter 3 - Program 3 *)
  2. MODULE CardMath;
  3.  
  4. FROM InOut IMPORT WriteLn, WriteString, WriteCard;
  5.  
  6. VAR CardSum, CardDif, CardMul, CardDiv : CARDINAL;
  7.     A, B, CardRem                      : CARDINAL;
  8.     IntVar                             : INTEGER;
  9.  
  10. BEGIN
  11.    A := 9;              (* Simple assignment                  *)
  12.    B := A + 4;          (* Addition                           *)
  13.    CardSum := A + B;    (* Addition                           *)
  14.    CardDif := B - A;    (* Subtraction                        *)
  15.    CardMul := A * B;    (* Multiplication                     *)
  16.    CardDiv := B DIV A;  (* Integer division, the result is a
  17.                           truncated integer number.          *)
  18.    CardRem := B MOD A;  (* d is the remainder of the integer
  19.                           division.                          *)
  20.    A := (A + B) DIV (3*B + 7);  (* Composite math statement  *)
  21.  
  22.    WriteString("The cardinal values are ");
  23.    WriteCard(CardSum,6);
  24.    WriteCard(CardDif,6);
  25.    WriteCard(CardMul,6);
  26.    WriteCard(CardDiv,6);
  27.    WriteCard(CardRem,6);
  28.    WriteLn;
  29.  
  30.    IntVar := A;       (* INTEGER and CARDINAL are assignment  *)
  31.    B := IntVar + 27;  (* compatible, but cannot be mixed in   *)
  32.                       (* any expression.                      *)
  33.  
  34.    A := 125;          (* CARDINAL assignment                  *)
  35.    B := A - 112;      (* CARDINAL math                        *)
  36. (* B := 125 + (-112);    Illegal CARDINAL Math - see text     *)
  37.  
  38.    IntVar := 125 + (-112);       (* INTEGER math, OK here     *)
  39.  
  40.    INC(A);      (* This increments the value of A       *)
  41.    DEC(A);      (* This decrements the value of A       *)
  42.    INC(A,4);    (* This adds 4 to the value of A        *)
  43.    DEC(A,6);    (* THis subtracts 6 from the value of A *)
  44.  
  45.    A := MIN(CARDINAL);  (* This produces the minimum CARDINAL *)
  46.    B := MAX(CARDINAL);  (* This produces the maximum CARDINAL *)
  47.  
  48. END CardMath.
  49.  
  50.  
  51.  
  52.  
  53. (* Result of execution
  54.  
  55. The cardinal values are     22     4   117     1     4
  56.  
  57. *)
  58.  
  59.